namespace RivercrabNet
{
    using System;
    using System.Collections.Generic;
    using System.Data;

    public class IndicatorOnBalanceVolume : BaseIndicator
    {
        private LineShape tlsObv;

        public IndicatorOnBalanceVolume()
        {
            base.IndType = IndicatorType.OBV;
            base.IndName = "OBV";
            base.IndDesc = "平衡交易量";
            base.SourceDic["Close"] = "";
            base.SourceDic["Volume"] = "";
            base.fields = new string[] { "OBV" };
        }

        public override bool Contains(object obj)
        {
            return (obj == this.tlsObv);
        }

        public override double[] Get(int r)
        {
            double num = 0.0;
            double num2 = Convert.ToDouble(base.Crab.DataSource.Rows[r][base.SourceDic["Close"]]);
            double num3 = Convert.ToDouble(base.Crab.DataSource.Rows[r][base.SourceDic["Volume"]]);
            double num4 = 0.0;
            if (r > 0)
            {
                num4 = Convert.ToDouble(base.Crab.DataSource.Rows[r - 1][base.SourceDic["Close"]]);
                num = Convert.ToDouble(base.Crab.DataSource.Rows[r - 1][this.tlsObv.Name]);
            }
            if (num2 > num4)
            {
                num += num3;
            }
            else if (num2 < num4)
            {
                num -= num3;
            }
            return new double[] { num };
        }

        public override List<BaseShape> GetShapeList()
        {
            return new List<BaseShape> { this.tlsObv };
        }

        public override void Remove()
        {
            base.Crab.DeleteShape(this.TlsObv);
        }

        public override bool Set(int r, string target)
        {
            try
            {
                DataRow row = base.Crab.DataSource.Rows[r];
                foreach (string str in base.SourceDic.Values)
                {
                    if ((str == target) || (target == null))
                    {
                        foreach (string str2 in base.SourceDic.Values)
                        {
                            if (row[str2] is DBNull)
                            {
                                return false;
                            }
                        }
                        double num = this.Get(r)[0];
                        base.Crab.SetValue(this.TlsObv.Name, num, r);
                        return true;
                    }
                }
                return false;
            }
            catch
            {
                return false;
            }
        }

        public override void SetParam(string[] fields, string[] source, double[] periods, int panelID)
        {
            this.TlsObv = base.Crab.AddLine(fields[0], panelID);
            base.SourceDic["Close"] = source[0];
            base.SourceDic["Volume"] = source[1];
        }

        public LineShape TlsObv
        {
            get
            {
                return this.tlsObv;
            }
            set
            {
                this.tlsObv = value;
            }
        }
    }
}

